home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games2 / rotise12.zip / TRANSACT.C < prev    next >
C/C++ Source or Header  |  1992-04-03  |  16KB  |  565 lines

  1. /* transact.c
  2.     Jonathan Arnold 1991
  3.  
  4.     All the functions to do transactions during the season.  Ones like:
  5.         move - change slots for a player
  6.         release - remove player from roster and send to free agent pool
  7.         claim - claim player in free agent pool
  8.         reserve - add player to rotisserie team's reserve
  9.         activate - activate a player off the reserve
  10.         trade - trade player from one rotisserie team to another
  11.         expand - do September roster expansion
  12. */
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #ifdef __TURBOC__
  17. #include <stdlib.h>
  18. #else
  19. #include <malloc.h>
  20. #endif
  21.  
  22. #include "rotise.h"
  23.  
  24. /* External data referenced */
  25. extern CMDLIST CmdTable[];                    /* cmdtable.c */
  26. extern int Cmd;                                /* rotise.c */
  27. extern int InputLine;                        /*  Line # of current file */
  28. extern BOOL Verbose;                            /*  How talkative to be */
  29. extern char *InputFilename;                /*  Filename being read */
  30. extern RDB_TEAM *RotoTeams;                /* roster.c - First team in list */
  31. extern int Weeks;                                /* stenog.c - How many intervals read in */
  32. extern char IntvDate[MAX_DATE+1];        /*  Date string for current interval */
  33. extern int SalFree;                            /*  Free agent salary */
  34. extern int CostRelease;
  35. extern int CostClaim;
  36. extern int CostReserve;
  37. extern int CostExpand;
  38. extern int CostWClaim;
  39. extern int CostActive;
  40.  
  41. /* External routines used */
  42.     /* NONE */
  43.  
  44. /* Local data publicly available */
  45.     /* NONE */
  46.  
  47. /* Local routine prototypes */
  48. BOOL move PROTO( (int token, char *tokens[]) );
  49. BOOL release PROTO( (int token, char *tokens[]) );
  50. BOOL claim PROTO( (int token, char *tokens[]) );
  51. BOOL reserve PROTO( (int token, char *tokens[]) );
  52. BOOL activate PROTO( (int token, char *tokens[]) );
  53. BOOL trade PROTO( (int token, char *tokens[]) );
  54. BOOL expand PROTO( (int token, char *tokens[]) );
  55.  
  56. /* Private data */
  57.     /* NONE */
  58.  
  59. /*
  60.     BOOL move( int tokcnt, char *tokens[] )
  61.      Move a player from one slot to another.
  62.  
  63.  ACCEPTS:
  64.     int tokcnt - how many tokens on this line
  65.     char *tokens[] - array pointing to each token
  66.  
  67.  RETURNS:
  68.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  69. */
  70.  
  71. #define ARG_MV_RTEAM    1                        /* Rotisserie team */
  72. #define ARG_MV_PK1    2                        /* Player key, last name */
  73. #define ARG_MV_PK2    3                        /* Player key, first initial */
  74. #define ARG_MV_SLOT    4                        /* New slot */
  75.  
  76. BOOL move ARGLIST( (tokcnt, tokens) )
  77.     NFARG( int tokcnt )
  78.     FARG( char *tokens[] )
  79. {
  80.     int slotN;
  81.     RDB_TEAM *rteam;
  82.     RDB_PLAYER *player;
  83.  
  84.     if ( tokcnt < ARG_MV_SLOT )
  85.         ARGCNT_ERR();
  86.  
  87.     VERBOSE( 4, "\Move %s to slot ", tokens[ARG_MV_PK1] );
  88.     VERBOSE( 4, "%s.\n", tokens[ARG_MV_SLOT] );
  89.  
  90.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  91.     { /* find the team */
  92.         if ( strcmp( rteam->key, tokens[ARG_MV_RTEAM] ) == 0 )
  93.             break;
  94.     }
  95.  
  96.     if ( rteam == NULL )
  97.     { /* couldn't find it */
  98.         rdb_error( "Move  - Roto team Not Found: ", tokens[ARG_MV_RTEAM] );
  99.         return TRUE;
  100.     }
  101.  
  102.     for ( player = rteam->players; player != NULL; player = player->next )
  103.     { /* now, see if we can find player on active roster */
  104.         if ( player->status == STATUS_ACTIVE )
  105.         { /* found active player, is this the one */
  106.             if ( stricmp( player->pname.pn_lname, tokens[ARG_MV_PK1] ) == 0 &&
  107.                 stricmp( player->pname.pn_fname, tokens[ARG_MV_PK2] ) == 0 )
  108.             { /* found the player */
  109.                 break;
  110.             }
  111.         }
  112.     }
  113.  
  114.     if ( player == NULL )
  115.     { /* unable to find player on active roster */
  116.         rdb_error( "Move - Player not on active roster: ", tokens[ARG_MV_PK1] );
  117.         return TRUE;
  118.     }
  119.  
  120.     /* change the slot */
  121.     slotN = slot_find( tokens[ARG_MV_SLOT] );
  122.     if ( slotN < 0 )
  123.     { /* bad slot */
  124.         rdb_error( "Move - Invalid slot: ", tokens[ARG_MV_SLOT] );
  125.         return TRUE;
  126.     }
  127.     player->slot = slotN;
  128.  
  129.     return TRUE;
  130. }
  131.  
  132. /*
  133.     BOOL release( int tokcnt, char *tokens[] )
  134.      Release a player from a rotisserie team and add him to the free agent
  135.     pool
  136.  
  137.  ACCEPTS:
  138.     int tokcnt - how many tokens on this line
  139.     char *tokens[] - array pointing to each token
  140.  
  141.  RETURNS:
  142.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  143. */
  144.  
  145. #define ARG_REL_TEAM        1                    /* Team doing release */
  146. #define ARG_REL_PK1        2                    /* Player key, last name */
  147. #define ARG_REL_PK2        3                    /* Player key, first initial */
  148. #define ARG_REL_WAIVE    4                    /* Being waived? */
  149.  
  150. BOOL release ARGLIST( (tokcnt, tokens) )
  151.     NFARG( int tokcnt )
  152.     FARG( char *tokens[] )
  153. {
  154.     RDB_TEAM *rteam;
  155.     RDB_PLAYER *player;
  156.     PDATA *pdata;
  157.  
  158.     if ( tokcnt < ARG_REL_WAIVE )
  159.         ARGCNT_ERR();
  160.  
  161.     VERBOSE( 4, "\tRelease from %s: ", tokens[ARG_REL_TEAM] );
  162.     VERBOSE( 4, "%s.\n", tokens[ARG_REL_PK1] );
  163.  
  164.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  165.     { /* find the team */
  166.         if ( strcmp( rteam->key, tokens[ARG_REL_TEAM] ) == 0 )
  167.             break;
  168.     }
  169.  
  170.     if ( rteam == NULL )
  171.     { /* couldn't find it */
  172.         rdb_error( "Release  - Team Not Found: ", tokens[ARG_REL_TEAM] );
  173.         return TRUE;
  174.     }
  175.  
  176.     for ( player = rteam->players; player != NULL; player = player->next )
  177.     { /* now, see if we can find player on active roster */
  178.         if ( player->status != STATUS_OLD )
  179.         { /* found active player, is this the one */
  180.             if ( stricmp( player->pname.pn_lname, tokens[ARG_REL_PK1] ) == 0 &&
  181.                 stricmp( player->pname.pn_fname, tokens[ARG_REL_PK2] ) == 0 )
  182.             { /* found the player */
  183.                 break;
  184.             }
  185.         }
  186.     }
  187.  
  188.     if ( player == NULL )
  189.     { /* unable to find player on active roster */
  190.         rdb_error( "Release - Player not on active roster: ", tokens[ARG_REL_PK1] );
  191.         return TRUE;
  192.     }
  193.  
  194.     if ( player->status != STATUS_RESERVE )
  195.         player->end = Weeks;
  196.     player->status = STATUS_OLD;
  197.  
  198.     pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
  199.                                              TRUE );
  200.     if ( pdata == NULL )
  201.     { /* try to find as pitcher */
  202.         pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
  203.                                              FALSE );
  204.     }
  205.     pdata->zorch = PLAYER_FREE;
  206.  
  207.     if ( tokcnt == (ARG_REL_WAIVE+1) )
  208.     { /* waived parameter passed, so add to waiver wire */
  209.         pdb_status( &player->pname, WAIVED_STRING, IntvDate, PLAYER_FREE, Weeks );
  210.     }
  211.     else
  212.     { /* otherwise, just release */
  213.         pdb_status( &player->pname, "", IntvDate, PLAYER_FREE, Weeks );
  214.     }
  215.  
  216.     rteam->money_spent += CostRelease;
  217.  
  218.     return TRUE;
  219. }
  220. /*
  221.     BOOL claim( int tokcnt, char *tokens[] )
  222.      Claim a player from the free agent pool.
  223.  
  224.  ACCEPTS:
  225.     int tokcnt - how many tokens on this line
  226.     char *tokens[] - array pointing to each token
  227.  
  228.  RETURNS:
  229.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  230. */
  231.  
  232. #define ARG_CLM_TEAM     1                    /* Rotisserie Team Key */
  233. #define ARG_CLM_PK1        2                    /* Player Key 1 - last name */
  234. #define ARG_CLM_PK2        3                    /* Player Key 2 - first initial(s) */
  235. #define ARG_CLM_SLOT        4                    /* Slot */
  236. #define ARG_CLM_NAME        5                    /* First word of full name */
  237.  
  238. BOOL claim ARGLIST( (tokcnt, tokens) )
  239.     NFARG( int tokcnt )
  240.     FARG( char *tokens[] )
  241. {
  242.     RDB_TEAM *rteam;
  243.     RDB_PLAYER *player, *wplayer;
  244.     PDATA *pdata;
  245.     char salary[20];
  246.     char contract[5];
  247.     int kk;
  248.     int slotN;
  249.     char batter;
  250.  
  251.     if ( tokcnt < ARG_CLM_NAME )
  252.         ARGCNT_ERR();
  253.  
  254.     VERBOSE( 4, "\tClaim for %s,", tokens[ARG_CLM_TEAM] );
  255.     VERBOSE( 4, " %s.\n", tokens[ARG_CLM_PK1] );
  256.  
  257.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  258.     { /* find the team */
  259.         if ( strcmp( rteam->key, tokens[ARG_CLM_TEAM] ) == 0 )
  260.             break;
  261.     }
  262.     
  263.     if ( rteam == NULL )
  264.     { /* couldn't find it */
  265.         rdb_error( "Claim  - Team Not Found: ", tokens[ARG_CLM_TEAM] );
  266.         return TRUE;
  267.     }
  268.  
  269.     pdata = pdb_pdata( tokens[ARG_CLM_PK1], tokens[ARG_CLM_PK2],
  270.                                              batter = TRUE );
  271.     if ( pdata == NULL )
  272.     { /* try to find as pitcher */
  273.         pdata = pdb_pdata( tokens[ARG_CLM_PK1], tokens[ARG_CLM_PK2],
  274.                                              batter = FALSE );
  275.     }
  276.  
  277.     if ( pdata == NULL || pdata->zorch != PLAYER_FREE )
  278.     { /* not a free agent; bummer man */
  279.         rdb_error( "Claim - Player not free agent: ", tokens[ARG_CLM_PK1] );
  280.     }
  281.  
  282.     slotN = slot_find( tokens[ARG_CLM_SLOT] );
  283.     if ( slotN < 0 )
  284.     { /* bad slot */
  285.         rdb_error( "Claim - Invalid slot: ", tokens[ARG_CLM_SLOT] );
  286.         return TRUE;
  287.     }
  288.  
  289.     player = (RDB_PLAYER *)calloc( 1, sizeof( RDB_PLAYER ) );
  290.  
  291.     if ( player == NULL )
  292.     { /* couldn't get memory, so quit */
  293.         rdb_error( "Claim - Unable to get memory!", NULL );
  294.         return FALSE;
  295.     }
  296.  
  297.     /* now muck with the tokens to use build_player to set up player data */
  298.     for ( kk = ARG_CLM_NAME; kk < tokcnt; kk++ )
  299.     { /* move full name to where build_player wants it */
  300.         tokens[ARG_ADD_NAME+(kk-ARG_CLM_NAME)] = tokens[kk];
  301.     }
  302.  
  303.     /* get free agent salary */
  304.     sprintf( salary, "%d", SalFree );
  305.     tokens[ARG_ADD_SAL] = salary;
  306.  
  307.     /* free agent has first year contract */
  308.     contract[0] = 'A';
  309.     contract[1] = '\0';
  310.     tokens[ARG_ADD_CONT] = contract;
  311.  
  312.     build_player( player, ARG_ADD_NAME+(kk-ARG_CLM_NAME), tokens );
  313.     player->pname.batter = batter;
  314.  
  315.     if ( rteam->players == NULL )
  316.     { /* first player - probably shouldn't happen with claim! */
  317.         rteam->players = player;
  318.     }
  319.     else
  320.     { /* find last one */
  321.         for ( wplayer = rteam->players; wplayer->next != NULL; wplayer = wplayer->next )
  322.         { /* skip through the list to find last one */
  323.         }
  324.         wplayer->next = player;
  325.     }
  326.     player->start = Weeks + 1;
  327.     player->end = Weeks + 1;
  328.  
  329.     /* add to cost based on whether this is a waiver claim */
  330.     if ( pdata != NULL && strcmp( pdata->status, WAIVED_STRING ) == 0 )
  331.     { /* on waivers */
  332.         rteam->money_spent += CostWClaim;
  333.     }
  334.     else
  335.     { /* free agent claim */
  336.         rteam->money_spent += CostClaim;
  337.     }
  338.  
  339.     /* set data to show no longer a free agent */
  340.     pdb_status( &player->pname, "", IntvDate, PLAYER_CLAIMED, Weeks+1 );
  341.  
  342.     return TRUE;
  343. }
  344. /*
  345.     BOOL reserve( int tokcnt, char *tokens[] )
  346.      Reserve a player.  Move player from the active roster onto a team's reserve
  347.     list.
  348.  
  349.  ACCEPTS:
  350.     int tokcnt - how many tokens on this line
  351.     char *tokens[] - array pointing to each token
  352.  
  353.  RETURNS:
  354.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  355. */
  356.  
  357. #define ARG_RES_TEAM     1                    /* Rotisserie team keyword */
  358. #define ARG_RES_PK1        2                    /* Player key 1 - last name */
  359. #define ARG_RES_PK2        3                    /* Player key 2 - first name */
  360.  
  361. BOOL reserve ARGLIST( (tokcnt, tokens) )
  362.     NFARG( int tokcnt )
  363.     FARG( char *tokens[] )
  364. {
  365.     RDB_TEAM *rteam;
  366.     RDB_PLAYER *player;
  367.  
  368.     if ( tokcnt < (ARG_RES_PK2+1) )
  369.         ARGCNT_ERR();
  370.  
  371.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  372.     { /* find the team */
  373.         if ( strcmp( rteam->key, tokens[ARG_RES_TEAM] ) == 0 )
  374.             break;
  375.     }
  376.     
  377.     if ( rteam == NULL )
  378.     { /* couldn't find it */
  379.         rdb_error( "Reserve  - Team Not Found: ", tokens[ARG_RES_TEAM] );
  380.         return TRUE;
  381.     }
  382.  
  383.     for ( player = rteam->players; player != NULL; player = player->next )
  384.     { /* now, see if we can find player on active roster */
  385.         if ( player->status == STATUS_ACTIVE )
  386.         { /* found active player, is this the one */
  387.             if ( stricmp( player->pname.pn_lname, tokens[ARG_RES_PK1] ) == 0 &&
  388.                 stricmp( player->pname.pn_fname, tokens[ARG_RES_PK2] ) == 0 )
  389.             { /* found the player */
  390.                 break;
  391.             }
  392.         }
  393.     }
  394.  
  395.     if ( player == NULL )
  396.     { /* unable to find player on active roster */
  397.         rdb_error( "Reserve - Player not on active roster: ", tokens[ARG_RES_PK1] );
  398.         return TRUE;
  399.     }
  400.  
  401. /*    player->end = (Weeks>=player->start?Weeks:player->start);  */
  402.     player->end = Weeks;
  403.     player->status = STATUS_RESERVE;
  404.  
  405.     rteam->money_spent += CostReserve;
  406.  
  407.     return TRUE;
  408. }
  409. /*
  410.     BOOL activate( int tokcnt, char *tokens[] )
  411.      Move a player from the reserve list onto the active roster.
  412.  
  413.  ACCEPTS:
  414.     int tokcnt - how many tokens on this line
  415.     char *tokens[] - array pointing to each token
  416.  
  417.  RETURNS:
  418.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  419. */
  420.  
  421. #define ARG_ACT_TEAM        1                    /* Rotisserie team keyword */
  422. #define ARG_ACT_PK1        2                    /* Player key 1 - last name */
  423. #define ARG_ACT_PK2        3                    /* Player key 2 - first name */
  424. #define ARG_ACT_SLOT        4                    /* Optional new slot */
  425.  
  426. BOOL activate ARGLIST( (tokcnt, tokens) )
  427.     NFARG( int tokcnt )
  428.     FARG( char *tokens[] )
  429. {
  430.     RDB_TEAM *rteam;
  431.     RDB_PLAYER *player, *wplayer;
  432.     RDB_SLOT *slotP;
  433.     PDATA *pdata;
  434.     char salary[10];
  435.  
  436.     if ( tokcnt < (ARG_ACT_PK2+1) )
  437.         ARGCNT_ERR();
  438.  
  439.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  440.     { /* find the team */
  441.         if ( strcmp( rteam->key, tokens[ARG_ACT_TEAM] ) == 0 )
  442.             break;
  443.     }
  444.     
  445.     if ( rteam == NULL )
  446.     { /* couldn't find it */
  447.         rdb_error( "Activate  - Team Not Found: ", tokens[ARG_ACT_TEAM] );
  448.         return TRUE;
  449.     }
  450.  
  451.     for ( player = rteam->players; player != NULL; player = player->next )
  452.     { /* now, see if we can find player on reserved roster */
  453.         if ( player->status == STATUS_RESERVE )
  454.         { /* found reserved player, is this the one */
  455.             if ( stricmp( player->pname.pn_lname, tokens[ARG_ACT_PK1] ) == 0 &&
  456.                 stricmp( player->pname.pn_fname, tokens[ARG_ACT_PK2] ) == 0 )
  457.             { /* found the player */
  458.                 break;
  459.             }
  460.         }
  461.     }
  462.  
  463.     if ( player == NULL )
  464.     { /* unable to find player on reserved roster */
  465.         rdb_error( "Activate - Player not on reserved roster: ", tokens[ARG_ACT_PK1] );
  466.         return TRUE;
  467.     }
  468.  
  469.     /* make player be old now and create a new one */
  470.     player->status = STATUS_OLD;
  471.  
  472.     /* now muck with the tokens to use build_player to set up player data */
  473.     if ( tokcnt <= ARG_ACT_SLOT )
  474.     { /* no slot, use old player one */
  475.         slotP = slot_get( player->slot );
  476.         tokens[ARG_ADD_SLOT] = ( slotP == NULL ) ? "??" : slotP->slot;
  477.     }
  478.     else
  479.     { /* use passed one */
  480.         tokens[ARG_ADD_SLOT] = tokens[ARG_ACT_SLOT];
  481.     }
  482.  
  483.     tokens[ARG_ADD_NAME] = player->name;
  484.  
  485.     /* get old salary */
  486.     sprintf( salary, "%d", player->salary );
  487.     tokens[ARG_ADD_SAL] = salary;
  488.  
  489.     /* get old contract */
  490.     tokens[ARG_ADD_CONT] = contract_string( player->contract );
  491.  
  492.     player = (RDB_PLAYER *)calloc( 1, sizeof( RDB_PLAYER ) );
  493.  
  494.     if ( player == NULL )
  495.     { /* couldn't get memory, so quit */
  496.         rdb_error( "Activate - Unable to get memory!", NULL );
  497.         return FALSE;
  498.     }
  499.  
  500.     build_player( player, ARG_ADD_NAME+1, tokens );
  501.  
  502.     /* find last one */
  503.     for ( wplayer = rteam->players; wplayer->next != NULL; wplayer = wplayer->next )
  504.     { /* skip through the list to find last one */
  505.     }
  506.     wplayer->next = player;
  507.  
  508.     player->start = Weeks + 1;
  509.     player->end = Weeks + 1;
  510.  
  511.     /* add to cost for activating */
  512.     rteam->money_spent += CostActive;
  513.  
  514.     /* now, clear status if he had one */
  515.     pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
  516.                                              TRUE );
  517.     if ( pdata == NULL )
  518.     { /* try to find as pitcher */
  519.         pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
  520.                                              FALSE );
  521.     }
  522.  
  523.     memset( pdata->status, 0, 5 );
  524.     memset( pdata->date, 0, MAX_DATE );
  525.  
  526.     return TRUE;
  527. }
  528. /*
  529.     BOOL trade( int tokcnt, char *tokens[] )
  530.      Trade player from one rotisserie team to another.
  531.  
  532.  ACCEPTS:
  533.     int tokcnt - how many tokens on this line
  534.     char *tokens[] - array pointing to each token
  535.  
  536.  RETURNS:
  537.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  538. */
  539.  
  540. BOOL trade ARGLIST( (tokcnt, tokens) )
  541.     NFARG( int tokcnt )
  542.     FARG( char *tokens[] )
  543. {
  544.     return TRUE;
  545. }
  546. /*
  547.     BOOL expand( int tokcnt, char *tokens[] )
  548.      Add a player to the roster.  No slot is associated with this player.  Usually
  549.     used for September roster expansion, which is now unlimited.
  550.  
  551.  ACCEPTS:
  552.     int tokcnt - how many tokens on this line
  553.     char *tokens[] - array pointing to each token
  554.  
  555.  RETURNS:
  556.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  557. */
  558.  
  559. BOOL expand ARGLIST( (tokcnt, tokens) )
  560.     NFARG( int tokcnt )
  561.     FARG( char *tokens[] )
  562. {
  563.     return TRUE;
  564. }
  565.